package cn.huhst.cas.weisiqian.service;

import java.util.ArrayList;

import cn.huhst.cas.weisiqian.dao.DuplicateEntryException;
import cn.huhst.cas.weisiqian.dao.PostDao;
import cn.huhst.cas.weisiqian.pojo.PostType;

public class PostService {

	private PostDao postdao = null;

	public PostService() {
		postdao = new PostDao();

	}

	public boolean addPostType(String posttype) throws PostTypeExistException {
		boolean result;
		try {
			result = postdao.addPostType(posttype);
		} catch (DuplicateEntryException e) {
			throw new PostTypeExistException(posttype + " 帖子分类已存在");
		}
		return result;
	}

	public int getPostTypeCount() {
		int count = postdao.getPostTypeCount();
		return count;
	}

	public ArrayList<PostType> getPostType(int pageIndex, int pageSize) {
		int recorderIndex = (pageIndex - 1) * pageSize;
		return postdao.getPostType(recorderIndex, pageSize);
	}

	public boolean deletePostType(String posttype) {
		int count = postdao.deletePostType(posttype);
		if (count > 0) {
			return true;
		} else {
			return false;
		}
	}

}
